package com.gagakuai.engine.impl.interceptor.defaultImpl;

import com.gagakuai.engine.impl.context.Context;
import com.gagakuai.engine.impl.interceptor.Command;
import com.gagakuai.engine.impl.interceptor.CommandConfig;
import com.gagakuai.engine.impl.interceptor.CommandInterceptor;

/*
 * @program: common-starters
 * @description: 命令调度执行者:作为拦截器链的最后一个，会在这里调度执行Command对象
 * @author: houhong
 * @create: 2023-01-01 23:56
 */
public class CommandInvoker extends AbstractCommandInterceptor {


    @Override
    public <T> T execute(CommandConfig config, Command<T> command) {

        return command.execute(Context.getCommandContext());
    }

    @Override
    public CommandInterceptor getNext() {
        return null;
    }

    @Override
    public void setNext(CommandInterceptor next) {
        throw new UnsupportedOperationException("CommandInvoker must be the last CommandInterceptor");
    }
}